package com.cn.learn.creator;

import lombok.extern.log4j.Log4j2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @ClassName CodeCreatorApplication
 * @Description 代码生成器的启动类
 * @Author JiJiang
 * @Date 2023/7/8 13:24
 * @Version 1.0
 */
@Log4j2
@SpringBootApplication
@MapperScan("com.cn.learn.creator.mapper")
public class CodeCreatorApplication {


    public static void main(String[] args) throws UnknownHostException {


        ConfigurableApplicationContext application = SpringApplication.run(CodeCreatorApplication.class);


        //获取环境变量对象
        Environment env = application.getEnvironment();
        //获取工程的ip
        String ip = InetAddress.getLocalHost().getHostAddress();
        //获取工程启动端口
        String port = env.getProperty("server.port");
        //获取项目访问的虚拟根目录
        String property = env.getProperty("server.servlet.context-path");
        //获取服务的访问路径
        String serverPath = env.getProperty("eureka.client.service-url.defaultZone");

        String path = property == null ? "" : property;
        log.info(
                "\n\t" +
                        "----------------------------------------------------------\n\t" +
                        "----------------------代码自动生成（code-creator）服务启动----------------\n\t" +
                        "Application Sailrui-Boot is running! Access URLs:\n\t" +
                        "本地访问地址: \t\thttp://localhost:" + port + path + "/\n\t" +
                        "外部访问地址: \thttp://" + ip + ":" + port + path + "/\n\t" +
                        "------------------------------------------------------------");


    }
}
